﻿package mortal.game.view.platform.platformThunder
{
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import fl.controls.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.platform.*;
    import mortal.game.view.yyZiZuan.*;
    import mortal.mvc.core.*;

    public class PlatformThunderVipPanel extends PlatformBasePanel
    {
        private var _lv2GiftItem:BaseItem;
        private var _lv2GiftList:GTileList;
        private var _lv2GetBtn:GButton;
        private var _lv2GiftName:GTextFiled;
        private var _yearGiftItem:BaseItem;
        private var _yearGiftList:GTileList;
        private var _yearGetBtn:GButton;
        private var _yearGiftName:GTextFiled;
        private var _kaitongBtn:GLoadingButton;

        public function PlatformThunderVipPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ThunderGoldBg, 4, 35, this));
            this._lv2GiftName = UIFactory.gTextField("牛X金钻LV2礼包", 200 + 382 - 27 - 10, 200 + 4, 400, 30, this, GlobalStyle.textFormatAnjin.center().setSize(14));
            this._yearGiftName = UIFactory.gTextField("牛X金钻年费礼包", 200 + 382 - 27 - 10, 200 + 4 + 184, 400, 30, this, GlobalStyle.textFormatAnjin.center().setSize(14));
            this._lv2GiftItem = UICompomentPool.getUICompoment(BaseItem);
            this._lv2GiftItem.setItemStyle(ItemStyleConst.Big, ImagesConst.RewardItemBg, 4, 4);
            this._lv2GiftItem.x = 600 + 29 + 8;
            this._lv2GiftItem.y = 450 - 6 - 300 + 105;
            this.addChild(this._lv2GiftItem);
            this._lv2GiftList = UIFactory.tileList(517 + 140 + 15, 450 + 85 - 300 + 105, 500, 42, this);
            this._lv2GiftList.columnWidth = 50;
            this._lv2GiftList.rowHeight = 40;
            this._lv2GiftList.setStyle("cellRenderer", YYZiZuanGiftCellRender);
            this._lv2GiftList.direction = GBoxDirection.HORIZONTAL;
            this._lv2GetBtn = UIFactory.gButton("免费领取", 160 + 580 + 8, 401 + 81 - 300 + 105, 82, 27, this, "RedButton");
            this._lv2GetBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._lv2GetBtn.mouseEnabled = false;
            this._yearGiftItem = UICompomentPool.getUICompoment(BaseItem);
            this._yearGiftItem.setItemStyle(ItemStyleConst.Big, ImagesConst.RewardItemBg, 4, 4);
            this._yearGiftItem.x = 600 + 29 + 6;
            this._yearGiftItem.y = 450 - 6 - 7;
            this.addChild(this._yearGiftItem);
            this._yearGiftList = UIFactory.tileList(517 + 140 + 10 + 6, 450 + 85 - 7, 500, 42, this);
            this._yearGiftList.columnWidth = 50;
            this._yearGiftList.rowHeight = 40;
            this._yearGiftList.setStyle("cellRenderer", YYZiZuanGiftCellRender);
            this._yearGiftList.direction = GBoxDirection.HORIZONTAL;
            this._kaitongBtn = UIFactory.gLoadingButton(ResFileConst.thunderGoldBtn, 600 + 26, 200 - 139, 118, 44, this);
            this._kaitongBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._yearGetBtn = UIFactory.gButton("免费领取", 160 + 580 + 6, 401 + 81 - 7, 82, 27, this, "RedButton");
            this._yearGetBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._yearGetBtn.mouseEnabled = false;
            this.setLv2GiftShow(PlatformVIPGiftsUtil.lv2Gift.reward);
            this.setYearGiftShow(PlatformVIPGiftsUtil.yearGift.reward);
            this.refresh();
            return;
        }// end function

        private function onClickHandle(event:MouseEvent) : void
        {
            if (event.target == this._kaitongBtn)
            {
                GameUtil.gotoPlatformVipUpgrade();
            }
            else if (event.target == this._lv2GetBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PlatformRequestVIPGift, PlatformVIPGiftsUtil.lv2Gift.id));
            }
            else if (event.target == this._yearGetBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PlatformRequestVIPGift, PlatformVIPGiftsUtil.yearGift.id));
            }
            return;
        }// end function

        private function setLv2GiftShow(param1:int) : void
        {
            var _loc_2:DataProvider = null;
            var _loc_3:ItemGiftBagInfo = null;
            var _loc_4:Array = null;
            var _loc_5:Array = null;
            var _loc_6:ItemData = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:YYZiZuanGiftDataGroup = null;
            if (this._lv2GiftItem)
            {
                this._lv2GiftItem.itemCode = param1;
                this._lv2GiftItem.isBind = true;
            }
            if (this._lv2GiftList)
            {
                _loc_2 = new DataProvider();
                _loc_3 = new ItemData(param1).itemInfo as ItemGiftBagInfo;
                _loc_4 = _loc_3.itemList1.split("&");
                _loc_7 = _loc_4.length;
                _loc_8 = 0;
                while (_loc_8 < _loc_4.length)
                {
                    
                    _loc_5 = _loc_4[_loc_8].split("#");
                    _loc_9 = new YYZiZuanGiftDataGroup();
                    _loc_9.itemCode = int(_loc_5[1]);
                    _loc_9.itemAmount = _loc_5[2];
                    _loc_9.isBind = true;
                    _loc_2.addItem(_loc_9);
                    _loc_8++;
                }
                this._lv2GiftList.dataProvider = _loc_2;
                this._lv2GiftList.drawNow();
            }
            return;
        }// end function

        private function setYearGiftShow(param1:int) : void
        {
            var _loc_2:DataProvider = null;
            var _loc_3:ItemGiftBagInfo = null;
            var _loc_4:Array = null;
            var _loc_5:Array = null;
            var _loc_6:ItemData = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:YYZiZuanGiftDataGroup = null;
            if (this._yearGiftItem)
            {
                this._yearGiftItem.itemCode = param1;
                this._yearGiftItem.isBind = true;
            }
            if (this._yearGiftList)
            {
                _loc_2 = new DataProvider();
                _loc_3 = new ItemData(param1).itemInfo as ItemGiftBagInfo;
                _loc_4 = _loc_3.itemList1.split("&");
                _loc_7 = _loc_4.length;
                _loc_8 = 0;
                while (_loc_8 < _loc_4.length)
                {
                    
                    _loc_5 = _loc_4[_loc_8].split("#");
                    _loc_9 = new YYZiZuanGiftDataGroup();
                    _loc_9.itemCode = int(_loc_5[1]);
                    _loc_9.itemAmount = _loc_5[2];
                    _loc_9.isBind = true;
                    _loc_2.addItem(_loc_9);
                    _loc_8++;
                }
                this._yearGiftList.dataProvider = _loc_2;
                this._yearGiftList.drawNow();
            }
            return;
        }// end function

        override public function refresh() : void
        {
            var _loc_1:Boolean = false;
            this._lv2GiftName.text = new ItemData(PlatformVIPGiftsUtil.lv2Gift.reward).name;
            this._yearGiftName.text = new ItemData(PlatformVIPGiftsUtil.yearGift.reward).name;
            if (PlatformVIPGiftsUtil.getReceiveTypeByTPlatformGift(PlatformVIPGiftsUtil.lv2Gift) == PlatformVIPGiftGroup.CanReceive)
            {
                this.setCanGetStyle(this._lv2GetBtn);
                _loc_1 = true;
            }
            else if (PlatformVIPGiftsUtil.getReceiveTypeByTPlatformGift(PlatformVIPGiftsUtil.lv2Gift) == PlatformVIPGiftGroup.HasReceive)
            {
                this.setHasGetStyle(this._lv2GetBtn);
            }
            else if (PlatformVIPGiftsUtil.getReceiveTypeByTPlatformGift(PlatformVIPGiftsUtil.lv2Gift) == PlatformVIPGiftGroup.UnReceive)
            {
                this.setCanNotGetStyle(this._lv2GetBtn);
            }
            if (PlatformVIPGiftsUtil.getReceiveTypeByTPlatformGift(PlatformVIPGiftsUtil.yearGift) == PlatformVIPGiftGroup.CanReceive)
            {
                this.setCanGetStyle(this._yearGetBtn);
                _loc_1 = true;
            }
            else if (PlatformVIPGiftsUtil.getReceiveTypeByTPlatformGift(PlatformVIPGiftsUtil.yearGift) == PlatformVIPGiftGroup.HasReceive)
            {
                this.setHasGetStyle(this._yearGetBtn);
            }
            else if (PlatformVIPGiftsUtil.getReceiveTypeByTPlatformGift(PlatformVIPGiftsUtil.yearGift) == PlatformVIPGiftGroup.UnReceive)
            {
                this.setCanNotGetStyle(this._yearGetBtn);
            }
            return;
        }// end function

        private function setCanGetStyle(param1:Button) : void
        {
            param1.label = "免费领取";
            param1.mouseEnabled = true;
            param1.filters = [];
            EffectManager.glowFilterReg(param1);
            return;
        }// end function

        private function setHasGetStyle(param1:Button) : void
        {
            param1.mouseEnabled = false;
            param1.label = "已领取";
            EffectManager.glowFilterUnReg(param1);
            param1.filters = [FilterConst.colorFilter3];
            return;
        }// end function

        private function setCanNotGetStyle(param1:Button) : void
        {
            param1.mouseEnabled = false;
            param1.label = "免费领取";
            EffectManager.glowFilterUnReg(param1);
            param1.filters = [FilterConst.colorFilter3];
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._yearGiftItem.dispose(param1);
            this._yearGiftItem = null;
            this._yearGiftList.dispose(param1);
            this._yearGiftList = null;
            this._kaitongBtn.dispose(param1);
            this._kaitongBtn = null;
            this._yearGetBtn.dispose(param1);
            this._yearGetBtn = null;
            this._lv2GiftName.dispose(param1);
            this._lv2GiftName = null;
            this._yearGiftName.dispose(param1);
            this._yearGiftName = null;
            super.disposeImpl(param1);
            return;
        }// end function

    }
}
